package org.nbict.iot.protocol.util;

import com.greenpineyu.fel.FelEngine;
import com.greenpineyu.fel.FelEngineImpl;
import com.greenpineyu.fel.context.MapContext;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by songseven on 18/6/14.
 */
public class FelTask implements Runnable {

    private FelEngine fel;

    public FelTask(FelEngine fel) {
        this.fel = fel;
    }

    @Override
    public void run() {
        String express = "energy_storage_faulty_num*0.1";
        for (int i = 0; i < 100; i++) {
            //fel.getContext().set("num", i);
            MapContext ctx = new MapContext();
            ctx.set("energy_storage_faulty_num", i);

            //System.out.println(fel.eval(express, ctx).toString());
            //System.out.println(new BigDecimal(fel.eval(express, ctx).toString()).floatValue());
            //BigDecimal b =  new BigDecimal((Double) fel.eval(express, ctx));
            //System.out.println(Thread.currentThread() + " : " + i + " ==> " + b.doubleValue());
        }
    }
    
    public static void main(String[] args) throws InterruptedException {

        ExecutorService executorService = Executors.newFixedThreadPool(1);

        FelEngine engine = new FelEngineImpl();

        for (int i = 0; i < 1; i++) {
            executorService.submit(new FelTask(engine));
        }
        Thread.sleep(5000);
        executorService.shutdown();
    }
}
